<template>
  <el-dialog
    :title="!dataForm.projectId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="编号" prop="projectNo" label-width="auto">
      <el-input v-model="dataForm.projectNo" placeholder="编号"></el-input>
    </el-form-item>
    <el-form-item label="项目名" prop="projectName" label-width="auto">
      <el-input v-model="dataForm.projectName" placeholder="项目名"></el-input>
    </el-form-item>
    <el-form-item label="立项时间" prop="projectApproveTime" label-width="auto">
<!--      <el-input v-model="dataForm.projectApproveTime" placeholder="立项时间"></el-input>-->
      <el-date-picker
        v-model="dataForm.projectApproveTime"
        align="right"
        type="date"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="评审时间" prop="projectReviewTime" label-width="auto">
<!--      <el-input v-model="dataForm.projectReviewTime" placeholder="评审时间"></el-input>-->
      <el-date-picker
        v-model="dataForm.projectReviewTime"
        align="right"
        type="date"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="上线时间" prop="projectOnlineTime" label-width="auto">
<!--      <el-input v-model="dataForm.projectOnlineTime" placeholder="上线时间"></el-input>-->
      <el-date-picker
        v-model="dataForm.projectOnlineTime"
        align="right"
        type="date"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="工作量" prop="projectLoad" label-width="auto">
      <el-input v-model="dataForm.projectLoad" placeholder="工作量标识"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="projectState" label-width="auto">
      <el-input v-model="dataForm.projectState" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="项目经理" prop="projectManager" label-width="auto">
      <el-input v-model="dataForm.projectManager" placeholder="项目经理"></el-input>
    </el-form-item>
    <el-form-item label="质量经理" prop="projectQualityManager" label-width="auto">
      <el-input v-model="dataForm.projectQualityManager" placeholder="质量经理"></el-input>
    </el-form-item>
    <el-form-item label="立项部门" prop="projectApproveDepartment" label-width="auto">
      <el-input v-model="dataForm.projectApproveDepartment" placeholder="立项部门"></el-input>
    </el-form-item>
    <el-form-item label="主导方" prop="projectLeadGroup" label-width="auto">
      <el-input v-model="dataForm.projectLeadGroup" placeholder="主导项目组"></el-input>
    </el-form-item>
    <el-form-item label="所属平台" prop="projectPlatform" label-width="auto">
      <el-input v-model="dataForm.projectPlatform" placeholder="所属平台"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          projectId: 0,
          projectNo: '',
          projectName: '',
          projectApproveTime: '',
          projectReviewTime: '',
          projectOnlineTime: '',
          projectLoad: '',
          projectState: '',
          projectManager: '',
          projectQualityManager: '',
          projectApproveDepartment: '',
          projectLeadGroup: '',
          projectPlatform: ''
        },
        dataRule: {
          projectNo: [
            { required: true, message: '编号不能为空', trigger: 'blur' }
          ],
          projectName: [
            { required: true, message: '项目名不能为空', trigger: 'blur' }
          ],
          projectApproveTime: [
            { required: true, message: '立项时间不能为空', trigger: 'blur' }
          ],
          projectReviewTime: [
            { required: true, message: '评审时间不能为空', trigger: 'blur' }
          ],
          projectOnlineTime: [
            { required: true, message: '上线时间不能为空', trigger: 'blur' }
          ],
          projectLoad: [
            { required: true, message: '工作量标识不能为空', trigger: 'blur' }
          ],
          projectState: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          projectManager: [
            { required: true, message: '项目经理不能为空', trigger: 'blur' }
          ],
          projectQualityManager: [
            { required: true, message: '质量经理不能为空', trigger: 'blur' }
          ],
          projectApproveDepartment: [
            { required: true, message: '立项部门不能为空', trigger: 'blur' }
          ],
          projectLeadGroup: [
            { required: true, message: '主导项目组不能为空', trigger: 'blur' }
          ],
          projectPlatform: [
            { required: true, message: '所属平台不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.projectId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.projectId) {
            this.$http({
              url: this.$http.adornUrl(`/project/pginoino/info/${this.dataForm.projectId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.projectNo = data.pginoino.projectNo
                this.dataForm.projectName = data.pginoino.projectName
                this.dataForm.projectApproveTime = data.pginoino.projectApproveTime
                this.dataForm.projectReviewTime = data.pginoino.projectReviewTime
                this.dataForm.projectOnlineTime = data.pginoino.projectOnlineTime
                this.dataForm.projectLoad = data.pginoino.projectLoad
                this.dataForm.projectState = data.pginoino.projectState
                this.dataForm.projectManager = data.pginoino.projectManager
                this.dataForm.projectQualityManager = data.pginoino.projectQualityManager
                this.dataForm.projectApproveDepartment = data.pginoino.projectApproveDepartment
                this.dataForm.projectLeadGroup = data.pginoino.projectLeadGroup
                this.dataForm.projectPlatform = data.pginoino.projectPlatform
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/project/pginoino/${!this.dataForm.projectId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'projectId': this.dataForm.projectId || undefined,
                'projectNo': this.dataForm.projectNo,
                'projectName': this.dataForm.projectName,
                'projectApproveTime': this.dataForm.projectApproveTime,
                'projectReviewTime': this.dataForm.projectReviewTime,
                'projectOnlineTime': this.dataForm.projectOnlineTime,
                'projectLoad': this.dataForm.projectLoad,
                'projectState': this.dataForm.projectState,
                'projectManager': this.dataForm.projectManager,
                'projectQualityManager': this.dataForm.projectQualityManager,
                'projectApproveDepartment': this.dataForm.projectApproveDepartment,
                'projectLeadGroup': this.dataForm.projectLeadGroup,
                'projectPlatform': this.dataForm.projectPlatform
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
                console.log(this.dataForm.projectApproveTime)
              }
            })
          }
        })
      }
    }
  }
</script>
